Open
Conversation
e774818 to
a1f47be
Compare
ehuss
reviewed
Mar 4, 2026
ec0193c to
00c5777
Compare
This comment has been minimized.
This comment has been minimized.
37c772b to
97e58c4
Compare
ehuss
reviewed
Mar 10, 2026
97e58c4 to
4d9d363
Compare
ehuss
approved these changes
Mar 10, 2026
10 tasks
Edited-by: TC Fixed conflicts due to #2199. No other changes.
4d9d363 to
a88e3b7
Compare
Collaborator
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
277d087 to
e8e679f
Compare
DanielEScherzer
approved these changes
Mar 11, 2026
The prior commit added a grammar for frontmatter, but the grammar notation available at the time that commit was prepared couldn't express all of the invariants the language requires. Opening and closing fences must have the same dash count. Indented fences must be rejected as an error. And once an opening fence is recognized, the parser must commit -- it can't backtrack and reinterpret the dashes as tokens. Since then, we've added named range repeats, hard cut, and negative lookahead to the grammar notation. With these, we can express the invariants directly. In this commit, we rewrite the frontmatter grammar. Named range repeats let the closing fence reference the opening fence's dash count. Hard cut commits the parse after the opening dashes. And `FRONTMATTER_INVALID` uses hard cut followed by the bottom rule (`^ ⊥`) to express that indented fences are a recognized-and-rejected syntactic form. We also add `⊥` as a primitive rule in the Notation chapter, move `HORIZONTAL_WHITESPACE` to Whitespace, and fix some minor editorial matters such as indentation and comment style.
The fence description uses the phrase "a matching pair of hyphens",
which can be misread as describing exactly two individual hyphens.
The constraints on fence length and matching are also compressed into
a single sentence with a trailing subclause ("from 3 to 255") that
reads as nonrestrictive.
Let's give each constraint its own sentence: what a fence is, where
it must appear, the length bounds on the opening fence, the matching
requirement for the closing fence, and trailing whitespace. This
makes the structure clearer.
The infostring sentence uses an inverted construction ("Following the
opening fence may be an infostring"); it's a bit awkward.
Let's use active voice and tighten the phrasing.
The body restriction sentence combines two unrelated constraints -- the hyphen-line restriction and the carriage-return ban -- in a single sentence joined by "or". This makes "or carriage returns" read as parallel to "hyphens", as though the line could maybe start with carriage returns. Let's split these into two separate sentences so that each constraint stands on its own.
The prose mentions "horizontal whitespace" in two places (fence trailing content and infostring trailing content) without linking to the grammar definition. Since `HORIZONTAL_WHITESPACE` is now a defined rule in Whitespace, let's add a link so readers can click through to the precise definition.
The frontmatter removal section could do better at describing the removal behavior. Let's rewrite the section with a precise description of the removal process and add an annotated example.
The `frontmatter.document` rule said "Frontmatter may only be preceded by a shebang and whitespace", where the "and" could be misread as requiring both a shebang and whitespace rather than listing the set of things allowed to precede frontmatter. Since we merged the shebang prose revision (#2192), the shebang position rule now reads as a positive statement of where the shebang may appear. Let's follow the same pattern here: state positively where frontmatter may appear rather than leaning on "only" and a negative constraint. We'll also rename the rule identifier to `frontmatter.position` in keeping with our conventions.
The example under `frontmatter.intro` used an external crate, a nontrivial script body, and a bare `rust` code block that would fail CI since the test runner doesn't support frontmatter. Let's simplify it to mirror the example in the frontmatter removal section of `input-format.md`, and let's wrap it in an `EXAMPLE` admonition consistent with our convention for examples that aren't demonstrating the behavior of a specific rule.
The intro under `frontmatter.intro` said "an optional section for content intended for external tools without requiring these tools to have full knowledge of the Rust grammar." This was a negative construction (what frontmatter doesn't require) rather than a positive one (what it is and what it enables). In this commit, we rewrite the intro as "an optional section of metadata whose syntax allows external tools to read it without parsing Rust." This tells the reader three things in one sentence: what frontmatter is, who it's for, and the key design property.
For the `WHITESPACE` grammar rule, we cite `Pattern_White_Space`. For `HORIZONTAL_WHITESPACE`, we hadn't cited provenance. Let's do that. Horizontal whitespace, in a Unicode context, is defined by UAX 31, Section 4.1, which categorizes `Pattern_White_Space` into line endings, ignorable format controls, and horizontal space. The horizontal space category is exactly the two characters our grammar specifies.
Many of our existing chapters start directly with the grammar. We're shifting, however, toward leading with the introduction and with the introductory example. Let's do that for the frontmatter chapter.
e8e679f to
526c143
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds Reference text for frontmatter.
Stabilization:
Tracking:
frontmatterrust#136889Original PR:
cc @ehuss @epage